package com;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.Statement;
import java.sql.ResultSet;
import javax.servlet.http.HttpSession;
import java.sql.SQLException;
import java.io.IOException;
import java.util.Vector;

public class Loginto extends HttpServlet{
	public void doGet(HttpServletRequest req,HttpServletResponse res){
	   String user = (String)req.getParameter("user");//��ȡ�û����������Ϣ
	   if(user==null)user="";
	   String password = (String)req.getParameter("password");
	   if(password==null)password="";
	   if(user.equals("admin"))
	   {
		   try {
			res.sendRedirect("/xiaonei1227/guanliyuan/shen_manager.jsp");
			return;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	   }
	   Statement stm = DbSQL.getstm();
	   HttpSession session = req.getSession(true);
	   if(stm!=null)
	   {  
	      try{
	      ResultSet rs = stm.executeQuery("select * from user1 where account = '"+user+"' and password='"+password+"'");
	      if(rs!=null){
	         if(rs.next()){
	         	//�������������ô��һ��һ�����ǿյģ�ֱ����ת����ҳ
	         	session.setAttribute("Login","Yes");
	         	System.out.println(""+rs.getString(3));
	         	session.setAttribute("nickname",(String)rs.getString(3));
	         	session.setAttribute("user",user);
	         	session.setAttribute("NoHavePeople","0");
	         	System.out.println("**");
	         	res.sendRedirect("/xiaonei1227/dl.jsp");
	         }else{
	         	System.out.println("û�������������Ϣ����ע���˺ţ���");
	         	session.setAttribute("NoHavePeople","1");
	         	res.sendRedirect("/xiaonei1227/dl.jsp");//����Ҫ��ʾû�д��˵���Ϣ
	         }
	         rs.close();
	      }
	      DbSQL.closestm();
	      DbSQL.closestm();
	      }catch(SQLException e){
	      	 e.printStackTrace();
	      }catch(IOException e){
	         e.printStackTrace();
	      }
	   }
	}
	public void doPost(HttpServletRequest req,HttpServletResponse res){
	   this.doGet(req,res);	  
	}
}